package com.hd.platform.util.image;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

/**初始化
 * Created by qingshengzheng on 17/5/5.
 */
public class ImageIndexInit {
    private static PhashIndex phashIndex=new PhashIndex();
    private static  ImagePHash imagePHash=ImagePHash.getInstance();
    public static  PhashIndex getPhashIndex()
    {
        return phashIndex;
    }
    /**
     *
     * @param args
     * @throws Exception
     */
    public static void main(String args[]) throws Exception {
        String filepath="";
        searchFile(filepath);



    }


    /**
     * 构建phash索引?树
     * @param filepath
     * @throws Exception
     */
    public static  void searchFile(String filepath) throws Exception{
        File folder = new File(filepath);
        File[] subFolders = folder.listFiles();
        List<File> result = new ArrayList<File>();// 声明一个集合
        for (int i = 0;
             i < subFolders.length; i++)
        {// 循环显示文件夹或文件
            if (subFolders[i].isFile()) {
                //构建图片索引
                String path=subFolders[i].getAbsolutePath();
                String filename=subFolders[i].getName();
                String phash=MyImagePHash.getFingerprintPhash(subFolders[i].getAbsolutePath());
                ImgNode imgNode=new ImgNode(path,filename,phash);
                phashIndex.addFile(subFolders[i].getAbsolutePath(),imgNode);
                //文件phash写入磁盘文件
            } else {
                searchFile(subFolders[i].getAbsolutePath());

            }
        }


    }

}
